home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / phpMyAdmin / libraries / functions.js < prev    next >
Encoding:
JavaScript  |  2005-01-18  |  34.7 KB  |  1,044 lines

  1. /* $Id: functions.js,v 2.12 2005/01/18 15:30:30 lem9 Exp $ */
  2.  
  3.  
  4. /**
  5.  * Displays an confirmation box before to submit a "DROP DATABASE" query.
  6.  * This function is called while clicking links
  7.  *
  8.  * @param   object   the link
  9.  * @param   object   the sql query to submit
  10.  *
  11.  * @return  boolean  whether to run the query or not
  12.  */
  13. function confirmLinkDropDB(theLink, theSqlQuery)
  14. {
  15.     // Confirmation is not required in the configuration file
  16.     // or browser is Opera (crappy js implementation)
  17.     if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
  18.         return true;
  19.     }
  20.  
  21.     var is_confirmed = confirm(confirmMsgDropDB + '\n' + confirmMsg + ' :\n' + theSqlQuery);
  22.     if (is_confirmed) {
  23.         theLink.href += '&is_js_confirmed=1';
  24.     }
  25.  
  26.     return is_confirmed;
  27. } // end of the 'confirmLinkDropDB()' function
  28.  
  29. /**
  30.  * Displays an confirmation box before to submit a "DROP/DELETE/ALTER" query.
  31.  * This function is called while clicking links
  32.  *
  33.  * @param   object   the link
  34.  * @param   object   the sql query to submit
  35.  *
  36.  * @return  boolean  whether to run the query or not
  37.  */
  38. function confirmLink(theLink, theSqlQuery)
  39. {
  40.     // Confirmation is not required in the configuration file
  41.     // or browser is Opera (crappy js implementation)
  42.     if (confirmMsg == '' || typeof(window.opera) != 'undefined') {
  43.         return true;
  44.     }
  45.  
  46.     var is_confirmed = confirm(confirmMsg + ' :\n' + theSqlQuery);
  47.     if (is_confirmed) {
  48.         theLink.href += '&is_js_confirmed=1';
  49.     }
  50.  
  51.     return is_confirmed;
  52. } // end of the 'confirmLink()' function
  53.  
  54.  
  55. /**
  56.  * Displays an confirmation box before doing some action 
  57.  *
  58.  * @param   object   the message to display 
  59.  *
  60.  * @return  boolean  whether to run the query or not
  61.  */
  62. function confirmAction(theMessage)
  63. {
  64.     // TODO: Confirmation is not required in the configuration file
  65.     // or browser is Opera (crappy js implementation)
  66.     if (typeof(window.opera) != 'undefined') {
  67.         return true;
  68.     }
  69.  
  70.     var is_confirmed = confirm(theMessage);
  71.  
  72.     return is_confirmed;
  73. } // end of the 'confirmAction()' function
  74.  
  75.  
  76. /**
  77.  * Displays an error message if a "DROP DATABASE" statement is submitted
  78.  * while it isn't allowed, else confirms a "DROP/DELETE/ALTER" query before
  79.  * sumitting it if required.
  80.  * This function is called by the 'checkSqlQuery()' js function.
  81.  *
  82.  * @param   object   the form
  83.  * @param   object   the sql query textarea
  84.  *
  85.  * @return  boolean  whether to run the query or not
  86.  *
  87.  * @see     checkSqlQuery()
  88.  */
  89. function confirmQuery(theForm1, sqlQuery1)
  90. {
  91.     // Confirmation is not required in the configuration file
  92.     if (confirmMsg == '') {
  93.         return true;
  94.     }
  95.  
  96.     // The replace function (js1.2) isn't supported
  97.     else if (typeof(sqlQuery1.value.replace) == 'undefined') {
  98.         return true;
  99.     }
  100.  
  101.     // js1.2+ -> validation with regular expressions
  102.     else {
  103.         // "DROP DATABASE" statement isn't allowed
  104.         if (noDropDbMsg != '') {
  105.             var drop_re = new RegExp('DROP\\s+(IF EXISTS\\s+)?DATABASE\\s', 'i');
  106.             if (drop_re.test(sqlQuery1.value)) {
  107.                 alert(noDropDbMsg);
  108.                 theForm1.reset();
  109.                 sqlQuery1.focus();
  110.                 return false;
  111.             } // end if
  112.         } // end if
  113.  
  114.         // Confirms a "DROP/DELETE/ALTER" statement
  115.         //
  116.         // TODO: find a way (if possible) to use the parser-analyser
  117.         // for this kind of verification
  118.         // For now, I just added a ^ to check for the statement at
  119.         // beginning of expression
  120.  
  121.         var do_confirm_re_0 = new RegExp('^DROP\\s+(IF EXISTS\\s+)?(TABLE|DATABASE)\\s', 'i');
  122.         var do_confirm_re_1 = new RegExp('^ALTER\\s+TABLE\\s+((`[^`]+`)|([A-Za-z0-9_$]+))\\s+DROP\\s', 'i');
  123.         var do_confirm_re_2 = new RegExp('^DELETE\\s+FROM\\s', 'i');
  124.         if (do_confirm_re_0.test(sqlQuery1.value)
  125.             || do_confirm_re_1.test(sqlQuery1.value)
  126.             || do_confirm_re_2.test(sqlQuery1.value)) {
  127.             var message      = (sqlQuery1.value.length > 100)
  128.                              ? sqlQuery1.value.substr(0, 100) + '\n    ...'
  129.                              : sqlQuery1.value;
  130.             var is_confirmed = confirm(confirmMsg + ' :\n' + message);
  131.             // drop/delete/alter statement is confirmed -> update the
  132.             // "is_js_confirmed" form field so the confirm test won't be
  133.             // run on the server side and allows to submit the form
  134.             if (is_confirmed) {
  135.                 theForm1.elements['is_js_confirmed'].value = 1;
  136.                 return true;
  137.             }
  138.             // "DROP/DELETE/ALTER" statement is rejected -> do not submit
  139.             // the form
  140.             else {
  141.                 window.focus();
  142.                 sqlQuery1.focus();
  143.                 return false;
  144.             } // end if (handle confirm box result)
  145.         } // end if (display confirm box)
  146.     } // end confirmation stuff
  147.  
  148.     return true;
  149. } // end of the 'confirmQuery()' function
  150.  
  151.  
  152. /**
  153.  * Displays an error message if the user submitted the sql query form with no
  154.  * sql query, else checks for "DROP/DELETE/ALTER" statements
  155.  *
  156.  * @param   object   the form
  157.  *
  158.  * @return  boolean  always false
  159.  *
  160.  * @see     confirmQuery()
  161.  */
  162. function checkSqlQuery(theForm)
  163. {
  164.     var sqlQuery = theForm.elements['sql_query'];
  165.     var isEmpty  = 1;
  166.  
  167.     // The replace function (js1.2) isn't supported -> basic tests
  168.     if (typeof(sqlQuery.value.replace) == 'undefined') {
  169.         isEmpty      = (sqlQuery.value == '') ? 1 : 0;
  170.         if (isEmpty && typeof(theForm.elements['sql_file']) != 'undefined') {
  171.             isEmpty  = (theForm.elements['sql_file'].value == '') ? 1 : 0;
  172.         }
  173.         if (isEmpty && typeof(theForm.elements['sql_localfile']) != 'undefined') {
  174.             isEmpty  = (theForm.elements['sql_localfile'].value == '') ? 1 : 0;
  175.         }
  176.         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined') {
  177.             isEmpty  = (theForm.elements['id_bookmark'].value == null || theForm.elements['id_bookmark'].value == '');
  178.         }
  179.     }
  180.     // js1.2+ -> validation with regular expressions
  181.     else {
  182.         var space_re = new RegExp('\\s+');
  183.         if (typeof(theForm.elements['sql_file']) != 'undefined' &&
  184.                 theForm.elements['sql_file'].value.replace(space_re, '') != '') {
  185.             return true;
  186.         }
  187.         if (typeof(theForm.elements['sql_localfile']) != 'undefined' &&
  188.                 theForm.elements['sql_localfile'].value.replace(space_re, '') != '') {
  189.             return true;
  190.         }
  191.         if (isEmpty && typeof(theForm.elements['id_bookmark']) != 'undefined' &&
  192.                 (theForm.elements['id_bookmark'].value != null || theForm.elements['id_bookmark'].value != '') &&
  193.                 theForm.elements['id_bookmark'].selectedIndex != 0
  194.                 ) {
  195.             return true;
  196.         }
  197.         // Checks for "DROP/DELETE/ALTER" statements
  198.         if (sqlQuery.value.replace(space_re, '') != '') {
  199.             if (confirmQuery(theForm, sqlQuery)) {
  200.                 return true;
  201.             } else {
  202.                 return false;
  203.             }
  204.         }
  205.         theForm.reset();
  206.         isEmpty = 1;
  207.     }
  208.  
  209.     if (isEmpty) {
  210.         sqlQuery.select();
  211.         alert(errorMsg0);
  212.         sqlQuery.focus();
  213.         return false;
  214.     }
  215.  
  216.     return true;
  217. } // end of the 'checkSqlQuery()' function
  218.  
  219.  
  220. /**
  221.  * Displays an error message if an element of a form hasn't been completed and
  222.  * should be
  223.  *
  224.  * @param   object   the form
  225.  * @param   string   the name of the form field to put the focus on
  226.  *
  227.  * @return  boolean  whether the form field is empty or not
  228.  */
  229. function emptyFormElements(theForm, theFieldName)
  230. {
  231.     var isEmpty  = 1;
  232.     var theField = theForm.elements[theFieldName];
  233.     // Whether the replace function (js1.2) is supported or not
  234.     var isRegExp = (typeof(theField.value.replace) != 'undefined');
  235.  
  236.     if (!isRegExp) {
  237.         isEmpty      = (theField.value == '') ? 1 : 0;
  238.     } else {
  239.         var space_re = new RegExp('\\s+');
  240.         isEmpty      = (theField.value.replace(space_re, '') == '') ? 1 : 0;
  241.     }
  242.     if (isEmpty) {
  243.         theForm.reset();
  244.         theField.select();
  245.         alert(errorMsg0);
  246.         theField.focus();
  247.         return false;
  248.     }
  249.  
  250.     return true;
  251. } // end of the 'emptyFormElements()' function
  252.  
  253.  
  254. /**
  255.  * Ensures a value submitted in a form is numeric and is in a range
  256.  *
  257.  * @param   object   the form
  258.  * @param   string   the name of the form field to check
  259.  * @param   integer  the minimum authorized value
  260.  * @param   integer  the maximum authorized value
  261.  *
  262.  * @return  boolean  whether a valid number has been submitted or not
  263.  */
  264. function checkFormElementInRange(theForm, theFieldName, min, max)
  265. {
  266.     var theField         = theForm.elements[theFieldName];
  267.     var val              = parseInt(theField.value);
  268.  
  269.     if (typeof(min) == 'undefined') {
  270.         min = 0;
  271.     }
  272.     if (typeof(max) == 'undefined') {
  273.         max = Number.MAX_VALUE;
  274.     }
  275.  
  276.     // It's not a number
  277.     if (isNaN(val)) {
  278.         theField.select();
  279.         alert(errorMsg1);
  280.         theField.focus();
  281.         return false;
  282.     }
  283.     // It's a number but it is not between min and max
  284.     else if (val < min || val > max) {
  285.         theField.select();
  286.         alert(val + errorMsg2);
  287.         theField.focus();
  288.         return false;
  289.     }
  290.     // It's a valid number
  291.     else {
  292.         theField.value = val;
  293.     }
  294.  
  295.     return true;
  296. } // end of the 'checkFormElementInRange()' function
  297.  
  298. function checkTableEditForm(theForm, fieldsCnt)
  299. {
  300.     for (i=0; i<fieldsCnt; i++)
  301.     {
  302.         var id = "field_" + i + "_2";
  303.         var elm = getElement(id);
  304.         if (elm.value == 'VARCHAR' || elm.value == 'CHAR') {
  305.             elm2 = getElement("field_" + i + "_3");
  306.             val = parseInt(elm2.value);
  307.             elm3 = getElement("field_" + i + "_1");
  308.             if (isNaN(val) && elm3.value != "") {
  309.                 elm2.select();
  310.                 alert(errorMsg1);
  311.                 elm2.focus();
  312.                 return false;
  313.             }
  314.         }
  315.     }
  316.     return true;
  317. } // enf of the 'checkTableEditForm()' function
  318.  
  319.  
  320. /**
  321.  * Ensures the choice between 'transmit', 'zipped', 'gzipped' and 'bzipped'
  322.  * checkboxes is consistant
  323.  *
  324.  * @param   object   the form
  325.  * @param   string   a code for the action that causes this function to be run
  326.  *
  327.  * @return  boolean  always true
  328.  */
  329. function checkTransmitDump(theForm, theAction)
  330. {
  331.     var formElts = theForm.elements;
  332.  
  333.     // 'zipped' option has been checked
  334.     if (theAction == 'zip' && formElts['zip'].checked) {
  335.         if (!formElts['asfile'].checked) {
  336.             theForm.elements['asfile'].checked = true;
  337.         }
  338.         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
  339.             theForm.elements['gzip'].checked = false;
  340.         }
  341.         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
  342.             theForm.elements['bzip'].checked = false;
  343.         }
  344.     }
  345.     // 'gzipped' option has been checked
  346.     else if (theAction == 'gzip' && formElts['gzip'].checked) {
  347.         if (!formElts['asfile'].checked) {
  348.             theForm.elements['asfile'].checked = true;
  349.         }
  350.         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
  351.             theForm.elements['zip'].checked = false;
  352.         }
  353.         if (typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked) {
  354.             theForm.elements['bzip'].checked = false;
  355.         }
  356.     }
  357.     // 'bzipped' option has been checked
  358.     else if (theAction == 'bzip' && formElts['bzip'].checked) {
  359.         if (!formElts['asfile'].checked) {
  360.             theForm.elements['asfile'].checked = true;
  361.         }
  362.         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
  363.             theForm.elements['zip'].checked = false;
  364.         }
  365.         if (typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked) {
  366.             theForm.elements['gzip'].checked = false;
  367.         }
  368.     }
  369.     // 'transmit' option has been unchecked
  370.     else if (theAction == 'transmit' && !formElts['asfile'].checked) {
  371.         if (typeof(formElts['zip']) != 'undefined' && formElts['zip'].checked) {
  372.             theForm.elements['zip'].checked = false;
  373.         }
  374.         if ((typeof(formElts['gzip']) != 'undefined' && formElts['gzip'].checked)) {
  375.             theForm.elements['gzip'].checked = false;
  376.         }
  377.         if ((typeof(formElts['bzip']) != 'undefined' && formElts['bzip'].checked)) {
  378.             theForm.elements['bzip'].checked = false;
  379.         }
  380.     }
  381.  
  382.     return true;
  383. } // end of the 'checkTransmitDump()' function
  384.  
  385.  
  386. /**
  387.  * This array is used to remember mark status of rows in browse mode
  388.  */
  389. var marked_row = new Array;
  390.  
  391.  
  392. /**
  393.  * Sets/unsets the pointer and marker in browse mode
  394.  *
  395.  * @param   object    the table row
  396.  * @param   integer  the row number
  397.  * @param   string    the action calling this script (over, out or click)
  398.  * @param   string    the default background color
  399.  * @param   string    the color to use for mouseover
  400.  * @param   string    the color to use for marking a row
  401.  *
  402.  * @return  boolean  whether pointer is set or not
  403.  */
  404. function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
  405. {
  406.     var theCells = null;
  407.  
  408.     // 1. Pointer and mark feature are disabled or the browser can't get the
  409.     //    row -> exits
  410.     if ((thePointerColor == '' && theMarkColor == '')
  411.         || typeof(theRow.style) == 'undefined') {
  412.         return false;
  413.     }
  414.  
  415.     // 2. Gets the current row and exits if the browser can't get it
  416.     if (typeof(document.getElementsByTagName) != 'undefined') {
  417.         theCells = theRow.getElementsByTagName('td');
  418.     }
  419.     else if (typeof(theRow.cells) != 'undefined') {
  420.         theCells = theRow.cells;
  421.     }
  422.     else {
  423.         return false;
  424.     }
  425.  
  426.     // 3. Gets the current color...
  427.     var rowCellsCnt  = theCells.length;
  428.     var domDetect    = null;
  429.     var currentColor = null;
  430.     var newColor     = null;
  431.     // 3.1 ... with DOM compatible browsers except Opera that does not return
  432.     //         valid values with "getAttribute"
  433.     if (typeof(window.opera) == 'undefined'
  434.         && typeof(theCells[0].getAttribute) != 'undefined') {
  435.         currentColor = theCells[0].getAttribute('bgcolor');
  436.         domDetect    = true;
  437.     }
  438.     // 3.2 ... with other browsers
  439.     else {
  440.         currentColor = theCells[0].style.backgroundColor;
  441.         domDetect    = false;
  442.     } // end 3
  443.  
  444.     // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
  445.     if (currentColor.indexOf("rgb") >= 0)
  446.     {
  447.         var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
  448.                                      currentColor.indexOf(')'));
  449.         var rgbValues = rgbStr.split(",");
  450.         currentColor = "#";
  451.         var hexChars = "0123456789ABCDEF";
  452.         for (var i = 0; i < 3; i++)
  453.         {
  454.             var v = rgbValues[i].valueOf();
  455.             currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
  456.         }
  457.     }
  458.  
  459.     // 4. Defines the new color
  460.     // 4.1 Current color is the default one
  461.     if (currentColor == ''
  462.         || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
  463.         if (theAction == 'over' && thePointerColor != '') {
  464.             newColor              = thePointerColor;
  465.         }
  466.         else if (theAction == 'click' && theMarkColor != '') {
  467.             newColor              = theMarkColor;
  468.             marked_row[theRowNum] = true;
  469.             // Garvin: deactivated onclick marking of the checkbox because it's also executed
  470.             // when an action (like edit/delete) on a single item is performed. Then the checkbox
  471.             // would get deactived, even though we need it activated. Maybe there is a way
  472.             // to detect if the row was clicked, and not an item therein...
  473.             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
  474.         }
  475.     }
  476.     // 4.1.2 Current color is the pointer one
  477.     else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
  478.              && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
  479.         if (theAction == 'out') {
  480.             newColor              = theDefaultColor;
  481.         }
  482.         else if (theAction == 'click' && theMarkColor != '') {
  483.             newColor              = theMarkColor;
  484.             marked_row[theRowNum] = true;
  485.             // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
  486.         }
  487.     }
  488.     // 4.1.3 Current color is the marker one
  489.     else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
  490.         if (theAction == 'click') {
  491.             newColor              = (thePointerColor != '')
  492.                                   ? thePointerColor
  493.                                   : theDefaultColor;
  494.             marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
  495.                                   ? true
  496.                                   : null;
  497.             // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
  498.         }
  499.     } // end 4
  500.  
  501.     // 5. Sets the new color...
  502.     if (newColor) {
  503.         var c = null;
  504.         // 5.1 ... with DOM compatible browsers except Opera
  505.         if (domDetect) {
  506.             for (c = 0; c < rowCellsCnt; c++) {
  507.                 theCells[c].setAttribute('bgcolor', newColor, 0);
  508.             } // end for
  509.         }
  510.         // 5.2 ... with other browsers
  511.         else {
  512.             for (c = 0; c < rowCellsCnt; c++) {
  513.                 theCells[c].style.backgroundColor = newColor;
  514.             }
  515.         }
  516.     } // end 5
  517.  
  518.     return true;
  519. } // end of the 'setPointer()' function
  520.  
  521. /*
  522.  * Sets/unsets the pointer and marker in vertical browse mode
  523.  *
  524.  * @param   object    the table row
  525.  * @param   integer   the column number
  526.  * @param   string    the action calling this script (over, out or click)
  527.  * @param   string    the default background color
  528.  * @param   string    the color to use for mouseover
  529.  * @param   string    the color to use for marking a row
  530.  *
  531.  * @return  boolean  whether pointer is set or not
  532.  *
  533.  * @author Garvin Hicking <me@supergarv.de> (rewrite of setPointer.)
  534.  */
  535. function setVerticalPointer(theRow, theColNum, theAction, theDefaultColor1, theDefaultColor2, thePointerColor, theMarkColor) {
  536.     var theCells = null;
  537.     var tagSwitch = null;
  538.  
  539.     // 1. Pointer and mark feature are disabled or the browser can't get the
  540.     //    row -> exits
  541.     if ((thePointerColor == '' && theMarkColor == '')
  542.         || typeof(theRow.style) == 'undefined') {
  543.         return false;
  544.     }
  545.  
  546.     if (typeof(document.getElementsByTagName) != 'undefined') {
  547.         tagSwitch = 'tag';
  548.     } else if (typeof(document.getElementById('table_results')) != 'undefined') {
  549.         tagSwitch = 'cells';
  550.     } else {
  551.         return false;
  552.     }
  553.  
  554.     // 2. Gets the current row and exits if the browser can't get it
  555.     if (tagSwitch == 'tag') {
  556.         theRows     = document.getElementById('table_results').getElementsByTagName('tr');
  557.         theCells    = theRows[1].getElementsByTagName('td');
  558.     } else if (tagSwitch == 'cells') {
  559.         theRows     = document.getElementById('table_results').rows;
  560.         theCells    = theRows[1].cells;
  561.     }
  562.  
  563.     // 3. Gets the current color...
  564.     var rowCnt         = theRows.length;
  565.     var domDetect      = null;
  566.     var currentColor   = null;
  567.     var newColor       = null;
  568.  
  569.     // 3.1 ... with DOM compatible browsers except Opera that does not return
  570.     //         valid values with "getAttribute"
  571.     if (typeof(window.opera) == 'undefined'
  572.         && typeof(theCells[theColNum].getAttribute) != 'undefined') {
  573.         currentColor = theCells[theColNum].getAttribute('bgcolor');
  574.         domDetect    = true;
  575.     }
  576.     // 3.2 ... with other browsers
  577.     else {
  578.         domDetect    = false;
  579.         currentColor = theCells[theColNum].style.backgroundColor;
  580.     } // end 3
  581.  
  582.     var c = null;
  583.  
  584.     // 4. Defines the new color
  585.     // 4.1 Current color is the default one
  586.     if (currentColor == ''
  587.         || currentColor.toLowerCase() == theDefaultColor1.toLowerCase()
  588.         || currentColor.toLowerCase() == theDefaultColor2.toLowerCase()) {
  589.         if (theAction == 'over' && thePointerColor != '') {
  590.             newColor              = thePointerColor;
  591.         } else if (theAction == 'click' && theMarkColor != '') {
  592.             newColor              = theMarkColor;
  593.             marked_row[theColNum] = true;
  594.         }
  595.     }
  596.     // 4.1.2 Current color is the pointer one
  597.     else if (currentColor.toLowerCase() == thePointerColor.toLowerCase() &&
  598.              (typeof(marked_row[theColNum]) == 'undefined' || !marked_row[theColNum]) || marked_row[theColNum] == false) {
  599.             if (theAction == 'out') {
  600.                 if (theColNum % 2) {
  601.                     newColor              = theDefaultColor1;
  602.                 } else {
  603.                     newColor              = theDefaultColor2;
  604.                 }
  605.             }
  606.             else if (theAction == 'click' && theMarkColor != '') {
  607.                 newColor              = theMarkColor;
  608.                 marked_row[theColNum] = true;
  609.             }
  610.     }
  611.     // 4.1.3 Current color is the marker one
  612.     else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
  613.         if (theAction == 'click') {
  614.             newColor              = (thePointerColor != '')
  615.                                   ? thePointerColor
  616.                                   : ((theColNum % 2) ? theDefaultColor1 : theDefaultColor2);
  617.             marked_row[theColNum] = false;
  618.         }
  619.     } // end 4
  620.  
  621.     // 5 ... with DOM compatible browsers except Opera
  622.  
  623.     for (c = 0; c < rowCnt; c++) {
  624.         if (tagSwitch == 'tag') {
  625.             Cells = theRows[c].getElementsByTagName('td');
  626.         } else if (tagSwitch == 'cells') {
  627.             Cells = theRows[c].cells;
  628.         }
  629.  
  630.         Cell  = Cells[theColNum];
  631.  
  632.         // 5.1 Sets the new color...
  633.         if (newColor) {
  634.             if (domDetect) {
  635.                 Cell.setAttribute('bgcolor', newColor, 0);
  636.             } else {
  637.                 Cell.style.backgroundColor = newColor;
  638.             }
  639.         } // end 5
  640.     } // end for
  641.  
  642.      return true;
  643.  } // end of the 'setVerticalPointer()' function
  644.  
  645. /**
  646.  * Checks/unchecks all tables
  647.  *
  648.  * @param   string   the form name
  649.  * @param   boolean  whether to check or to uncheck the element
  650.  *
  651.  * @return  boolean  always true
  652.  */
  653. function setCheckboxes(the_form, do_check)
  654. {
  655.     var elts      = (typeof(document.forms[the_form].elements['selected_db[]']) != 'undefined')
  656.                   ? document.forms[the_form].elements['selected_db[]']
  657.                   : (typeof(document.forms[the_form].elements['selected_tbl[]']) != 'undefined')
  658.           ? document.forms[the_form].elements['selected_tbl[]']
  659.           : document.forms[the_form].elements['selected_fld[]'];
  660.     var elts_cnt  = (typeof(elts.length) != 'undefined')
  661.                   ? elts.length
  662.                   : 0;
  663.  
  664.     if (elts_cnt) {
  665.         for (var i = 0; i < elts_cnt; i++) {
  666.             elts[i].checked = do_check;
  667.         } // end for
  668.     } else {
  669.         elts.checked        = do_check;
  670.     } // end if... else
  671.  
  672.     return true;
  673. } // end of the 'setCheckboxes()' function
  674.  
  675. /**
  676.  * Checks/unchecks all rows
  677.  *
  678.  * @param   string   the form name
  679.  * @param   boolean  whether to check or to uncheck the element
  680.  * @param   string   basename of the element
  681.  * @param   integer  min element count
  682.  * @param   integer  max element count
  683.  *
  684.  * @return  boolean  always true
  685.  */
  686. // modified 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
  687. // - set the other checkboxes (if available) too
  688. function setCheckboxesRange(the_form, do_check, basename, min, max)
  689. {
  690.     for (var i = min; i < max; i++) {
  691.         if (typeof(document.forms[the_form].elements[basename + i]) != 'undefined') {
  692.             document.forms[the_form].elements[basename + i].checked = do_check;
  693.         }
  694.         if (typeof(document.forms[the_form].elements[basename + i + 'r']) != 'undefined') {
  695.             document.forms[the_form].elements[basename + i + 'r'].checked = do_check;
  696.         }
  697.     }
  698.  
  699.     return true;
  700. } // end of the 'setCheckboxesRange()' function
  701.  
  702. // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
  703. //   copy the checked from left to right or from right to left
  704. //   so it's easier for users to see, if $cfg['ModifyAtRight']=true, what they've checked ;)
  705. function copyCheckboxesRange(the_form, the_name, the_clicked)
  706. {
  707.     if (typeof(document.forms[the_form].elements[the_name]) != 'undefined' && typeof(document.forms[the_form].elements[the_name + 'r']) != 'undefined') {
  708.         if (the_clicked !== 'r') {
  709.             if (document.forms[the_form].elements[the_name].checked == true) {
  710.                 document.forms[the_form].elements[the_name + 'r'].checked = true;
  711.             }else {
  712.                 document.forms[the_form].elements[the_name + 'r'].checked = false;
  713.             }
  714.         } else if (the_clicked == 'r') {
  715.             if (document.forms[the_form].elements[the_name + 'r'].checked == true) {
  716.                 document.forms[the_form].elements[the_name].checked = true;
  717.             }else {
  718.                 document.forms[the_form].elements[the_name].checked = false;
  719.             }
  720.        }
  721.     }
  722. }
  723.  
  724.  
  725. // added 2004-05-08 by Michael Keck <mail_at_michaelkeck_dot_de>
  726. //  - this was directly written to each td, so why not a function ;)
  727. //  setCheckboxColumn(\'id_rows_to_delete' . $row_no . ''\');
  728. function setCheckboxColumn(theCheckbox){
  729.     if (document.getElementById(theCheckbox)) {
  730.         document.getElementById(theCheckbox).checked = (document.getElementById(theCheckbox).checked ? false : true);
  731.         if (document.getElementById(theCheckbox + 'r')) {
  732.             document.getElementById(theCheckbox + 'r').checked = document.getElementById(theCheckbox).checked;
  733.         }
  734.     } else {
  735.         if (document.getElementById(theCheckbox + 'r')) {
  736.             document.getElementById(theCheckbox + 'r').checked = (document.getElementById(theCheckbox +'r').checked ? false : true);
  737.             if (document.getElementById(theCheckbox)) {
  738.                 document.getElementById(theCheckbox).checked = document.getElementById(theCheckbox + 'r').checked;
  739.             }
  740.         }
  741.     }
  742. }
  743.  
  744.  
  745. /**
  746.   * Checks/unchecks all options of a <select> element
  747.   *
  748.   * @param   string   the form name
  749.   * @param   string   the element name
  750.   * @param   boolean  whether to check or to uncheck the element
  751.   *
  752.   * @return  boolean  always true
  753.   */
  754. function setSelectOptions(the_form, the_select, do_check)
  755. {
  756.     var selectObject = document.forms[the_form].elements[the_select];
  757.     var selectCount  = selectObject.length;
  758.  
  759.     for (var i = 0; i < selectCount; i++) {
  760.         selectObject.options[i].selected = do_check;
  761.     } // end for
  762.  
  763.     return true;
  764. } // end of the 'setSelectOptions()' function
  765.  
  766. /**
  767.   * Inserts multiple fields.
  768.   *
  769.   */
  770. function insertValueQuery() {
  771.     var myQuery = document.sqlform.sql_query;
  772.     var myListBox = document.sqlform.dummy;
  773.  
  774.     if(myListBox.options.length > 0) {
  775.         var chaineAj = "";
  776.         var NbSelect = 0;
  777.         for(var i=0; i<myListBox.options.length; i++) {
  778.             if (myListBox.options[i].selected){
  779.                 NbSelect++;
  780.                 if (NbSelect > 1)
  781.                     chaineAj += ", ";
  782.                 chaineAj += myListBox.options[i].value;
  783.             }
  784.         }
  785.  
  786.         //IE support
  787.         if (document.selection) {
  788.             myQuery.focus();
  789.             sel = document.selection.createRange();
  790.             sel.text = chaineAj;
  791.             document.sqlform.insert.focus();
  792.         }
  793.         //MOZILLA/NETSCAPE support
  794.         else if (document.sqlform.sql_query.selectionStart || document.sqlform.sql_query.selectionStart == "0") {
  795.             var startPos = document.sqlform.sql_query.selectionStart;
  796.             var endPos = document.sqlform.sql_query.selectionEnd;
  797.             var chaineSql = document.sqlform.sql_query.value;
  798.  
  799.             myQuery.value = chaineSql.substring(0, startPos) + chaineAj + chaineSql.substring(endPos, chaineSql.length);
  800.         } else {
  801.             myQuery.value += chaineAj;
  802.         }
  803.     }
  804. }
  805.  
  806. /**
  807.   * listbox redirection
  808.   */
  809. function goToUrl(selObj, goToLocation) {
  810.     eval("document.location.href = '" + goToLocation + "pos=" + selObj.options[selObj.selectedIndex].value + "'");
  811. }
  812.  
  813. /**
  814.  * getElement
  815.  */
  816. function getElement(e,f){
  817.     if(document.layers){
  818.         f=(f)?f:self;
  819.         if(f.document.layers[e]) {
  820.             return f.document.layers[e];
  821.         }
  822.         for(W=0;i<f.document.layers.length;W++) {
  823.             return(getElement(e,fdocument.layers[W]));
  824.         }
  825.     }
  826.     if(document.all) {
  827.         return document.all[e];
  828.     }
  829.     return document.getElementById(e);
  830. }
  831.  
  832. /**
  833.   * Refresh the WYSIWYG-PDF scratchboard after changes have been made
  834.   */
  835. function refreshDragOption(e) {
  836.     myid = getElement(e);
  837.     if (myid.style.visibility == 'visible') {
  838.         refreshLayout();
  839.     }
  840. }
  841.  
  842. /**
  843.   * Refresh/resize the WYSIWYG-PDF scratchboard
  844.   */
  845. function refreshLayout() {
  846.         myid = getElement('pdflayout');
  847.  
  848.         if (document.pdfoptions.orientation.value == 'P') {
  849.             posa = 'x';
  850.             posb = 'y';
  851.         } else {
  852.             posa = 'y';
  853.             posb = 'x';
  854.         }
  855.  
  856.         myid.style.width = pdfPaperSize(document.pdfoptions.paper.value, posa) + 'px';
  857.         myid.style.height = pdfPaperSize(document.pdfoptions.paper.value, posb) + 'px';
  858. }
  859.  
  860. /**
  861.   * Show/hide the WYSIWYG-PDF scratchboard
  862.   */
  863. function ToggleDragDrop(e) {
  864.     myid = getElement(e);
  865.  
  866.     if (myid.style.visibility == 'hidden') {
  867.         init();
  868.         myid.style.visibility = 'visible';
  869.         myid.style.display = 'block';
  870.         document.edcoord.showwysiwyg.value = '1';
  871.     } else {
  872.         myid.style.visibility = 'hidden';
  873.         myid.style.display = 'none';
  874.         document.edcoord.showwysiwyg.value = '0';
  875.     }
  876. }
  877.  
  878. /**
  879.   * PDF scratchboard: When a position is entered manually, update
  880.   * the fields inside the scratchboard.
  881.   */
  882. function dragPlace(no, axis, value) {
  883.     if (axis == 'x') {
  884.         getElement("table_" + no).style.left = value + 'px';
  885.     } else {
  886.         getElement("table_" + no).style.top  = value + 'px';
  887.     }
  888. }
  889.  
  890. /**
  891.   * Returns paper sizes for a given format
  892.   */
  893. function pdfPaperSize(format, axis) {
  894.     switch (format.toUpperCase()) {
  895.         case '4A0':
  896.             if (axis == 'x') return 4767.87; else return 6740.79;
  897.             break;
  898.         case '2A0':
  899.             if (axis == 'x') return 3370.39; else return 4767.87;
  900.             break;
  901.         case 'A0':
  902.             if (axis == 'x') return 2383.94; else return 3370.39;
  903.             break;
  904.         case 'A1':
  905.             if (axis == 'x') return 1683.78; else return 2383.94;
  906.             break;
  907.         case 'A2':
  908.             if (axis == 'x') return 1190.55; else return 1683.78;
  909.             break;
  910.         case 'A3':
  911.             if (axis == 'x') return 841.89; else return 1190.55;
  912.             break;
  913.         case 'A4':
  914.             if (axis == 'x') return 595.28; else return 841.89;
  915.             break;
  916.         case 'A5':
  917.             if (axis == 'x') return 419.53; else return 595.28;
  918.             break;
  919.         case 'A6':
  920.             if (axis == 'x') return 297.64; else return 419.53;
  921.             break;
  922.         case 'A7':
  923.             if (axis == 'x') return 209.76; else return 297.64;
  924.             break;
  925.         case 'A8':
  926.             if (axis == 'x') return 147.40; else return 209.76;
  927.             break;
  928.         case 'A9':
  929.             if (axis == 'x') return 104.88; else return 147.40;
  930.             break;
  931.         case 'A10':
  932.             if (axis == 'x') return 73.70; else return 104.88;
  933.             break;
  934.         case 'B0':
  935.             if (axis == 'x') return 2834.65; else return 4008.19;
  936.             break;
  937.         case 'B1':
  938.             if (axis == 'x') return 2004.09; else return 2834.65;
  939.             break;
  940.         case 'B2':
  941.             if (axis == 'x') return 1417.32; else return 2004.09;
  942.             break;
  943.         case 'B3':
  944.             if (axis == 'x') return 1000.63; else return 1417.32;
  945.             break;
  946.         case 'B4':
  947.             if (axis == 'x') return 708.66; else return 1000.63;
  948.             break;
  949.         case 'B5':
  950.             if (axis == 'x') return 498.90; else return 708.66;
  951.             break;
  952.         case 'B6':
  953.             if (axis == 'x') return 354.33; else return 498.90;
  954.             break;
  955.         case 'B7':
  956.             if (axis == 'x') return 249.45; else return 354.33;
  957.             break;
  958.         case 'B8':
  959.             if (axis == 'x') return 175.75; else return 249.45;
  960.             break;
  961.         case 'B9':
  962.             if (axis == 'x') return 124.72; else return 175.75;
  963.             break;
  964.         case 'B10':
  965.             if (axis == 'x') return 87.87; else return 124.72;
  966.             break;
  967.         case 'C0':
  968.             if (axis == 'x') return 2599.37; else return 3676.54;
  969.             break;
  970.         case 'C1':
  971.             if (axis == 'x') return 1836.85; else return 2599.37;
  972.             break;
  973.         case 'C2':
  974.             if (axis == 'x') return 1298.27; else return 1836.85;
  975.             break;
  976.         case 'C3':
  977.             if (axis == 'x') return 918.43; else return 1298.27;
  978.             break;
  979.         case 'C4':
  980.             if (axis == 'x') return 649.13; else return 918.43;
  981.             break;
  982.         case 'C5':
  983.             if (axis == 'x') return 459.21; else return 649.13;
  984.             break;
  985.         case 'C6':
  986.             if (axis == 'x') return 323.15; else return 459.21;
  987.             break;
  988.         case 'C7':
  989.             if (axis == 'x') return 229.61; else return 323.15;
  990.             break;
  991.         case 'C8':
  992.             if (axis == 'x') return 161.57; else return 229.61;
  993.             break;
  994.         case 'C9':
  995.             if (axis == 'x') return 113.39; else return 161.57;
  996.             break;
  997.         case 'C10':
  998.             if (axis == 'x') return 79.37; else return 113.39;
  999.             break;
  1000.         case 'RA0':
  1001.             if (axis == 'x') return 2437.80; else return 3458.27;
  1002.             break;
  1003.         case 'RA1':
  1004.             if (axis == 'x') return 1729.13; else return 2437.80;
  1005.             break;
  1006.         case 'RA2':
  1007.             if (axis == 'x') return 1218.90; else return 1729.13;
  1008.             break;
  1009.         case 'RA3':
  1010.             if (axis == 'x') return 864.57; else return 1218.90;
  1011.             break;
  1012.         case 'RA4':
  1013.             if (axis == 'x') return 609.45; else return 864.57;
  1014.             break;
  1015.         case 'SRA0':
  1016.             if (axis == 'x') return 2551.18; else return 3628.35;
  1017.             break;
  1018.         case 'SRA1':
  1019.             if (axis == 'x') return 1814.17; else return 2551.18;
  1020.             break;
  1021.         case 'SRA2':
  1022.             if (axis == 'x') return 1275.59; else return 1814.17;
  1023.             break;
  1024.         case 'SRA3':
  1025.             if (axis == 'x') return 907.09; else return 1275.59;
  1026.             break;
  1027.         case 'SRA4':
  1028.             if (axis == 'x') return 637.80; else return 907.09;
  1029.             break;
  1030.         case 'LETTER':
  1031.             if (axis == 'x') return 612.00; else return 792.00;
  1032.             break;
  1033.         case 'LEGAL':
  1034.             if (axis == 'x') return 612.00; else return 1008.00;
  1035.             break;
  1036.         case 'EXECUTIVE':
  1037.             if (axis == 'x') return 521.86; else return 756.00;
  1038.             break;
  1039.         case 'FOLIO':
  1040.             if (axis == 'x') return 612.00; else return 936.00;
  1041.             break;
  1042.     } // end switch
  1043. }
  1044.